public class test02 {
        List<List<Integer>> res;
        List<Integer> list;
        int[] used;
        public List<List<Integer>> permuteUnique(int[] nums) {
            Arrays.sort(nums);
            res = new ArrayList<>();
            list = new ArrayList<>();
            used = new int[nums.length];
            Arrays.fill(used,0);
            backTracking(nums);
            return res;
        }
        private void backTracking(int[] nums){
            if(list.size()==nums.length){
                res.add(new ArrayList(list));
            }
            for(int i = 0;i<nums.length;i++){
                if(i>0 && nums[i]==nums[i-1] && used[i-1]==1){
                    continue;
                }
                if(used[i]==0){
                    used[i] = 1;
                    list.add(nums[i]);
                    backTracking(nums);
                    used[i] = 0;
                    list.removeLast();
                }

            }
        }
}
